package com.example.demo;

import lombok.extern.slf4j.Slf4j;
import org.grean.tools.base.res.ApiResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @author green_xukk
 * @since 2021/4/13
 */
@Controller
@Slf4j
@RequestMapping("/api")
public class TestController {

    @RequestMapping("/location/AnyAdd")
    @ResponseBody
    public Object locationAdd(@RequestBody Location location){
        log.warn("{}",location);
        return ApiResult.renderOk();
    }
    @RequestMapping("/sensingApi/AddData")
    @ResponseBody
    public Object dataAdd(@RequestBody HourData hourData){
        log.warn("{}",hourData);
        return "True";
    }
    @PostMapping("/upload")
    public Object uploadFile( @RequestParam("file") MultipartFile file,
                           @RequestParam("folder") String folder) {
        Map<String,Object> map=new HashMap<>(10);
        String url=new StringBuilder().append("/api/file/").append(folder).append("/").append(file.getOriginalFilename()).toString();
        map.put("url",url);
        return map;
    }
}
